<!--* 下拉树选择框组件-->
<!--* @module src/components/public-->
<!--* @desc 下拉选择框-->
<!--* @author chenyi-->
<!--* @date 2019年08月15日17:22:43-->

<template>
    <div>
      <el-cascader
          v-model="values"
          :options="list"
      >
      </el-cascader>
    </div>
</template>

<script>
  import {getEnum, getDict, getDataByUrl} from '../../api/getComData'
  import util from '../../libs/util'
  export default {
    name:'es-cascader',
    props: {
      multiple:Boolean,//是否多选
      dictName:String//字典
      ,enumName:String//枚举
      ,url:String //url
      ,value:[String,Array]
      ,disabled:Boolean//是否禁用
      ,collapseTags:Boolean//多选按文字显示
      ,showTip:Boolean//是否显示提示
      ,tipText:{
         type:String,
        default: "请选择"
      }
    },
    model:{
      event:'changeValue'
    },
    data: function () {
      return {
        list: [],
        values:this.value,
      }
    },
    mounted: function () {
      let _this = this
      if (_this.dictName) {
        _this.list = util.getLocalStorageItem(_this.dictName);
        if (!_this.list) {
          getDict({dictName: _this.dictName}).then((res) => {
            _this.list = res.data
            util.setLocalStorageItem(_this.dictName, res.data)
          })
        }
      } else if (_this.enumName) {
        _this.list =util.getLocalStorageItem(_this.enumName);
        if (!_this.list) {
          getEnum({enumName: _this.enumName}).then((res) => {
            _this.list = res.data
            util.setLocalStorageItem(_this.enumName, res.data)
          })
        }
      } else if (_this.url) {
        getDataByUrl(_this.url, {enumName: _this.enumName}).then((res) => {
          _this.list = res.data
        })
      } else{
        _this.$message.error("未指定数据源");
        return false;
      }
    },
    watch:{
      value:function (val) {
        this.values=val;
      },
      values:function (val) {
        this.$emit("changeValue",val);
      }
    }
  }
</script>

<style scoped>

</style>
